package com.cqs.leetcode.math;

/**
 * lixw
 * 2021/11/15
 **/
public class BulbSwitcher319 {



    public int bulbSwitch(int n) {
        return (int) Math.sqrt(n);
    }

    static class mock {
        //模拟超时
        public int bulbSwitch(int n) {
            int result = 0;
            for (int i = 1; i <= n; i++) {
                int cnt = cnt(i);
                //  System.out.print(i + ", cnt = " + cnt + "  ");
                if ((cnt % 2) == 1) { //奇数
                    result++;
                }
            }
            return result;
        }

        //约数
        private int cnt(final int n) {
            if (n == 1) return 1;
            int result = 0;
            int left = 0, right = n;
            while (++left <= right) {
                right = n / left;
                if (right < left) break;
                if (n % left == 0) {
                    int delta = left == right ? 1 : 2;
                    result += delta;
                }
            }
            return result;
        }
    }

    public static void main(String[] args) {


        BulbSwitcher319 b = new BulbSwitcher319();
        for (int i = 6; i < 100; i++) {
            System.out.println("i = " + i + ";result = " + b.bulbSwitch(i));
        }
        System.out.println("===");
        int start = 99999999;
        for (int i = start; i < start + 1000; i++) {
            System.out.println("i = " + i + " result = " + b.bulbSwitch(i));
        }


    }
}
